#!/bin/bash

# 如果java环境存在则退出
if [ "$(command -v go)" ]; then
    echo "go环境已经存在"
    exit 0
fi

# 检查是否安装了glibc.i686软件包
if ! rpm -q glibc.i686 >/dev/null 2>&1; then
    echo "未安装glibc.i686软件包"
    echo "正在通过yum安装glibc.i686..."
    yum install -y glibc.i686
    if [ $? -ne 0 ]; then
        echo "安装glibc.i686失败"
        exit 1
    fi
fi

# 继续执行其他操作
echo "glibc.i686已安装"

echo "开始安装go"

goPack="go1.20.5.linux-386.tar.gz"

if [ ! -f "$goPack" ];then
wget https://go.dev/dl/go1.20.5.linux-386.tar.gz
fi

# 解压安装包
tar -zxvf $goPack -C /usr/local
if [ $? -ne 0 ]; then
    echo "安装包解压失败"
    exit 1
fi

#创建存储文件资源目录,官方建议放在 /home/go
mkdir -p /home/go/bin /home/go/pkg /home/go/src

# 配置环境变量
echo '# go environment variables' >> /etc/profile
echo 'export GOROOT=/usr/local/go' >> /etc/profile
echo 'export GOPATH=/home/go ' >> /etc/profile
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> /etc/profile

# 重新加载配置文件
source /etc/profile

# 检查Go安装信息
echo "检查Go安装信息"
if [ "$(command -v go)" ]; then
    echo "Go安装成功" 
    java -version
    else
    echo "Go安装失败"
fi

